﻿package projectiles
{
	public class Yellow_Projectile extends Offensive_Projectile
	{
		public function Yellow_Projectile(sU:*, tU:*,gH:GameHandler,dmg_amt)
		{
			super(sU, tU,gH);
			this.y -= 10;
			var jitter_distance = 50;
			var jitter_width = 20;
			var done = false;
			this.graphics.lineStyle(2,0xE7FA11);
			this.attack_damage = dmg_amt;
			var count = 0;
			var spot_x = 0;
			var spot_y = 0;
			var fake_target_x = target.x - this.x;
			var fake_target_y = target.y - this.y;
			while(!done && count < 10){
				count ++;
				var dist_x = fake_target_x - spot_x;
				var dist_y = fake_target_y - spot_y;
				
				if(Math.abs(dist_x) + Math.abs(dist_y) < jitter_distance){
					this.graphics.lineTo(spot_x + dist_x,spot_y+dist_y);
					done = true;
				}else{
					var ang = Math.atan2(dist_y,dist_x);
					var tar_x = jitter_distance*Math.cos(ang);
					var tar_y = jitter_distance*Math.sin(ang);
					spot_x += tar_x;
					spot_y += tar_y;
					this.graphics.lineTo(spot_x,spot_y);
					this.graphics.moveTo(spot_x,spot_y);
					
					spot_x += Math.random()*jitter_width - jitter_width/2;;
					spot_y += Math.random()*jitter_width - jitter_width/2;;
					
					this.graphics.lineTo(spot_x,spot_y);
					
					this.graphics.moveTo(spot_x,spot_y);
				}
			}
			this.alpha = 1;
		}
		override public function run(){
			this.alpha -= .2;
			
			if(this.alpha <= 0)
				end_move();
		}
		override public function end_move(){
			if(died)
				return;
			target.hit("yellow",this.attack_damage);
			die();
		}
	}
}